﻿/*
必須引用xmlParser

*/


Ajax.prototype.callCSharpService = function(_url, _options) {
		//Must enable HTTP Post
		//原則上也是用post，但是要處理回傳的XML字串
		/* 回傳值是這個格式:
		<?xml version="1.0" encoding="utf-8"?>
		
		<string xmlns="http://tempuri.org/">Hello World</string>
		*/
		_options.parser = function(xmlString) {
			//alert(xmlString);
			var xml = new DOMParser().parseFromString(xmlString, 'text/xml');
			var xmlObject = parseXmlToObject(xml);

			if (xmlObject != null) {
				var text = JSON.stringify(xmlObject
				, function(key, value) {
					return this[key] instanceof Date ? 'JSDate:' + this[key] : value;
				});
				return text.indexOf('\\u') >= 0 ? UnicodeParser.decode(text) : text;
			} else {
				return null;
			}
		}

		return this.run('POST', _url, _options);
	}